import { getLocalMenu, saveLocalMenu } from "../utils";
import { getMenu } from "@/api";
import { MenuResponse } from "@/types"
import { ConsoleSqlOutlined } from "@ant-design/icons";
let currentJob: Promise<MenuResponse> | null // current-JOB是什么？
export function getMenus() {
  if (currentJob) {
    return currentJob
  }
  console.log('current',currentJob)
  const job: Promise<MenuResponse> = new Promise((resolve) => {
    let localMenu = getLocalMenu();
    if (localMenu) {
      localMenu.push(
        {
          m_id: 101,
          parent_m_id: null,
          title: "demo",
          path: "/demo",
          icon: "icon_set",
          keep_alive: "true",
          order: 10000,
          show: true
      }
      )
      return resolve(localMenu);
    }
    getMenu()
      .then((result) => {
        saveLocalMenu(result);
        resolve(result);
      })
      .catch((err) => {
        resolve([]);
      });
  });
  currentJob = job
  job.finally(() => { currentJob = null })
  return job
}
